<div class="steps">
    <div class="substeps">
        <div class="substepitmgray1 substepitmblue1">
            <b>01</b> 选择支付模式
        </div>
        <div class="substepitmgray2">
            <b>02</b> 填写金额
        </div>
        <div class="substepitmgray2">
            <b>03</b> 选择银行
        </div>
        <div class="substepitmgray2">
            <b>04</b> 充值到账
        </div>
        <div class="clear"></div>
    </div>
    <div class="line"></div>
    <div class="tabs charge-types">
        <div class="tabtitle">选择充值模式：</div>
        <div class="tab hide" id="tp_online_bank" value="bank_online">网银在线支付</div>
        <div class="tab tabactive" id="tp_bank" value="bank">银行卡汇款</div>
        <!-- 支付宝支付 -->
        <div class="tab hide" id="tp_online_zfb" value="alipay_online">支付宝在线支付</div>				
        <!-- 微信支付 -->
        <div class="tab hide" id="tp_online_wx" value="wechat_online">微信在线支付</div>	
        <!-- QQ支付 -->			
        <div class="tab hide" id="tp_online_qq" value="qq_online">QQ钱包在线支付</div>	
        <!-- 信用卡在线支付 -->			
        <div class="tab hide" id="tp_online_xyk" value="visa_online">信用卡在线支付</div>	
                    
        <div class="tab hide" id="tp_wx" value="wechat" init="true">人工微信收款</div>
        <div class="tab hide" id="tp_zfb" value="alipay" init="true">人工支付宝收款</div>
        <div class="tab hide" id="tp_cft" value="cft">人工QQ钱包收款</div>
        <div class="clear"></div>
    </div>
</div>

<div class="subcontent" id="subpagetp_bank">
</div>

<script>
$(function() {  
    var hadload = false;
    var thirds = null, banks = null, alipay = null, wechat = null, cft = null;
    var grade = context.user.user.layer || '0'; grade = grade + '';
    var _updateTypes = function() {
        if (thirds === null || banks === null || alipay === null || wechat === null || cft === null) return;

        var flag = false;
        for (var i in thirds) {
            var d = thirds[i];
            if (d.payType == 'bank') {
                flag = true; break;
            }
        }
        if (flag) $("#tp_online_bank").show();
        else $("#tp_online_bank").hide();

        // 银行卡汇款
        if (banks.length == 0) $("#tp_bank").hide();
        else $("#tp_bank").show();

        // 支付宝在线支付
        var flag = false;
        for (var i in thirds) {
            var d = thirds[i];
            if (d.payType == 'alipay') {
                flag = true; break;
            }
        }
        if (flag) $("#tp_online_zfb").show();
        else $("#tp_online_zfb").hide();

        // 微信在线支付
        var flag = false;
        for (var i in thirds) {
            var d = thirds[i];
            if (d.payType == 'wechat') {
                flag = true; break;
            }
        }
        if (flag) $("#tp_online_wx").show();
        else $("#tp_online_wx").hide();

        // QQ钱包在线支付
        var flag = false;
        for (var i in thirds) {
            var d = thirds[i];
            if (d.payType == 'qq') {
                flag = true; break;
            }
        }
        if (flag) $("#tp_online_qq").show();
        else $("#tp_online_qq").hide();

        // 人工微信
        if (wechat.length == 0) $("#tp_wx").hide();
        else $("#tp_wx").show();

        // 人工支付宝
        if (alipay.length == 0) $("#tp_zfb").hide();
        else $("#tp_zfb").show();

        // 人工qq
        if (cft.length == 0) $("#tp_cft").hide();
        else $("#tp_cft").show();

        // 设置个默认的
        var s = "";
        if ($("#tp_bank").css("display") != 'none') {
            s = "tp_bank";
        }
        else {
            var arr = $(".tabs .tab");
            for (var i  = 0; i < arr.length; i++) {
                if ($(arr[i]).css("display") != 'none') {
                    s = $(arr[i]).attr("value");
                    break;
                }
            }
        }
        $(".tabs .tab").removeClass("tabactive");
        $("#" + s).addClass("tabactive");
        if (s && !hadload) {
            hadload = true;
            switch_page("center/charge/" + s, $("#subpagetp_bank"));
        }
    };

    // 第三方
    CMD.pay_uquery(function(r) {
        thirds = [];
        console.log(r.list);
        for (var i in r.list) {
            var data = r.list[i];
            if (data.enable != 1) continue;
            data.layer = data.layer.split(",");
            if (data.layer.indexOf(grade) == -1) {
                continue;  
            }
            thirds.push(data);
        }
        _updateTypes();
    });

    // 银行转账
    Classify.queryExt("money", "banks", true, [], function(r) {
        banks = [];
        for (var i in r) {
            if (r[i].enable != 1) continue;
            if (r[i].layer.indexOf(grade) == -1) continue;
            banks.push(r[i]);
        }
        _updateTypes();
    });

    // 支付宝转账
    Classify.queryExt("money", "alipay", true, [], function(r) {
        alipay = [];
        for (var i in r) {
            if (r[i].enable != 1) continue;
            if (r[i].layer.indexOf(grade) == -1) continue;
            alipay.push(r[i]);
        }
        _updateTypes();
    });

    // 微信转账
    Classify.queryExt("money", "wechat", true, [], function(r) {
        wechat = [];
        for (var i in r) {
            if (r[i].enable != 1) continue;
            if (r[i].layer.indexOf(grade) == -1) continue;
            wechat.push(r[i]);
        }
        _updateTypes();
    });

    // 财付通
    Classify.queryExt("money", "cft", true, [], function(r) {
        cft = [];
        for (var i in r) {
            if (r[i].enable != 1) continue;
            if (r[i].layer.indexOf(grade) == -1) continue;
            cft.push(r[i]);
        }
        _updateTypes();
    });

    $(".charge-types .tab").click(function(e) {
        $(".charge-types .tab").removeClass("tabactive");
        $(e.currentTarget).addClass("tabactive");
        switch_page("center/charge/" + $(e.currentTarget).attr("value"), $("#subpagetp_bank"));
    });
    switch_page("center/charge/" + $(".charge-types .tabactive").attr("value"), $("#subpagetp_bank"));
});
</script>